package simorg.actions;

import simorg.controller.CourseController;
import simorg.domain.Course;
import simorg.domain.persistence.CourseTable;
import simorg.view.ModelView;
import simorg.view.WebSessionContext;

public class CourseNew extends Action {

	public static String actionName = "new";
	public CourseNew() {
		super(actionName);
		this.controllerName = CourseController.controllerName;
	}
	public CourseNew(String courseId) {
		super(actionName);
		this.controllerName = CourseController.controllerName;
		this.getRequestArgs().add(courseId);
	}
	
	@Override
	public ModelView checkAccess(WebSessionContext wc) throws Exception {
		return this.checkAdminAccess(wc);
	}
	
	@Override
	public ModelView process(WebSessionContext wc) throws Exception {
		Course c = new Course();
		c.setName("");
		c.setSemester("");
		c.setSection("");
		CourseTable.save(wc.getDbConnection(), c);
		Action redirect = new CourseView(String.valueOf(c.getId()));
		wc.redirectAdmin(redirect);
		return null;
	}

}
